package cn.edu.zut.dao;

import cn.edu.zut.domain.Notice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoticeDao {
    //添加通知
    @Insert("insert into notice(_id, title, content, time, receiver) values(#{_id}, #{title}, #{content}, #{time}, #{receiver})")
    public void add(Notice notice);
    //根据_id删除通知
    @Delete("delete from notice where _id = #{_id}")
    public void deleteById(int _id);
    //查询所有通知，根据_id降序排列
    @Select("select * from notice order by _id desc")
    public List<Notice> findAll();
    //查询所有通知
    @Select("select * from notice order by _id")
    public List<Notice> findAllByOrder();
    //修改通知
    @Update("update notice set title = #{title}, content = #{content}, time = #{time}, receiver = #{receiver} where _id = #{_id}")
    public void update(Notice notice);
    //根据_id查询通知
    @Select("select * from notice where _id = #{_id}")
    public Notice findByNoticeId(int _id);
    //根据标题查询通知，并根据_id降序排列
    @Select("select * from notice where title = #{title} order by _id desc")
    public List<Notice> findByTitle(String title);
}
